Skip to content

feat: support schema-qualified temporary tables - #495

Open
olmaks wants to merge 4 commits into
tekumara:mainfrom
olmaks:fix/qualified-temporary-tables
Open

olmaks wants to merge 4 commits into
tekumara:mainfrom
olmaks:fix/qualified-temporary-tables

Conversation

@olmaks

@olmaks olmaks commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Why?

dbt's native unit tests create their scratch relation with create or replace temporary table "DB"."S"."MODEL__dbt_tmp" as (...), then describe table it and drop it. Qualified temporary table names fail in fakesnow, because DuckDB keeps every temporary table in its session-wide temp catalog and rejects any other qualifier, so these tests can't run (#458). DESCRIBE of a temporary table also returned no columns, even unqualified.

How?

Temporary tables keep the Snowflake schema they were created in (the record TableStages already holds for table stages), and references that resolve to that schema are rewritten to DuckDB's temp.main. A temporary table therefore shadows a permanent table of the same name only in its own schema, and isn't found by its unqualified name from another schema. Temporary tables' VARCHAR lengths and comments are recorded per table rather than per name, so sessions no longer see each other's, and the records go when the table is replaced or dropped.

The first commit is what dbt needs; the other three (COPY INTO by qualified name, not finding a temporary table from another schema by its unqualified name, per-session metadata) are separate commits that can be dropped independently.

Fakesnow-specific limitations:

  • DuckDB holds one temporary table per name per session, ignoring case, so creating a temporary table whose name matches an existing one ignoring case — in another schema, or in the same schema with different case or quoting — is rejected with an explicit error; Snowflake would create a second table.
  • A temporary table is still found by a differently-cased unquoted name, as in DuckDB (unchanged).
  • Not covered: the source of CLONE when it's a qualified temporary table, ALTER TABLE ... RENAME and TRUNCATE of a qualified temporary table, three-part column references (db.schema.t.x), describe-only queries in server mode, and listing temporary tables in SHOW TABLES / INFORMATION_SCHEMA.TABLES.
  • COPY load history is still keyed by schema and table name, so a temporary table shares it with a permanent table and with other sessions' temporary tables of the same name (existing behaviour, happy to follow up).

Fixes #458

🤖 Generated with Claude Code

olmaks and others added 4 commits October 29, 2026 04:20
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ied name

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# Schema-qualified temporary tables fail, blocking native dbt unit tests

1 participant